<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <!-- 居中对其 -->
        <span style="font-size: 20px; display: block; text-align: center;">个人信息</span>
      </div>
      <div>
        <ul class="list-group list-group-striped">
          <li class="list-group-item">
            <svg-icon icon-class="user" />用户昵称
            <div class="pull-right">{{ user.nickName }}</div>
          </li>
          <li class="list-group-item">
            <svg-icon icon-class="phone" />手机号码
            <div class="pull-right">{{ user.phonenumber }}</div>
          </li>
          <li class="list-group-item">
            <svg-icon icon-class="email" />用户邮箱
            <div class="pull-right">{{ user.email }}</div>
          </li>
          <li class="list-group-item">
            <svg-icon icon-class="peoples" />所属角色
            <div class="pull-right">{{ roleGroup }}</div>
          </li>
          <li class="list-group-item">
            <svg-icon icon-class="date" />创建日期
            <div class="pull-right">{{ user.createTime }}</div>
          </li>

        </ul>
        <el-button @click="drawer = true" type="primary" style="margin-left: 16px;">
          更改信息
        </el-button>
      </div>
    </el-card>

    <el-drawer title="基本资料" :visible.sync="drawer" direction="rtl" :append-to-body="true" :before-close="handleClose" size="50%">
      <el-card>
        <div slot="header" class="clearfix">
          <span>基本资料</span>
        </div>
        <el-tabs v-model="activeTab">
          <el-tab-pane label="基本资料" name="userinfo">
            <userInfo :user="user" />
          </el-tab-pane>
          <el-tab-pane label="修改密码" name="resetPwd">
            <resetPwd />
          </el-tab-pane>
        </el-tabs>
      </el-card>
    </el-drawer>

  </div>
</template>

<script>

import userInfo from "./userInfo";
import resetPwd from "./resetPwd";
import { getUserProfile } from "@/api/system/user";

export default {
  name: "Profile",
  components: {  userInfo, resetPwd },
  data() {
    return {
      user: {},
      roleGroup: {},
      postGroup: {},
      activeTab: "userinfo",      
      auths: [],
      drawer: false,
    };
  },
  created() {
    this.getUser();
  },
  methods: {
    getUser() {
      getUserProfile().then(response => {
        this.user = response.data;
        this.roleGroup = response.roleGroup;
        this.postGroup = response.postGroup;
        this.auths = response.auths;
      });
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => { });
    }
  }
};
</script>

<style scoped >
.box-card{
  width: 30%;
  margin: 100px auto;
  
}

</style>